using System;
using System.Collections;

using System.IO;

namespace Antix.Mail
{
    /// <summary>
    /// Attachment object
    /// </summary>
    public class Attachment : MessageContent
    {
        #region Constructors etc.

        /// <summary>
        /// Create attachment
        /// </summary>
        public Attachment()
            : base()
        {
        }

        /// <summary>
        /// Create attachment
        /// </summary>
        public Attachment(MessageContentHeaders headers, string dataRaw)
            : base(headers, dataRaw)
        {
        }

        #endregion

        #region Properties

        #endregion

        #region Methods

        /// <summary>
        /// Save this attachment to disk
        /// </summary>
        public void Save(string path)
        {
            switch (this.Encoding)
            {
                case MessageContentEncodingType.Base64:
                    File.WriteAllBytes(path + this.FileName, Convert.FromBase64String(this.DataRaw));
                    break;
                default: // text
                    IOFunctions.CreateTextFile(path + this.FileName, this.Data);
                    break;
            }
        }

        #endregion
    }
}